package com.zy.servlet.user;

import com.zy.service.FindUserByIdService;
import com.zy.service.impl.FindUserByIdServiceImpl;
import com.zy.entity.User;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;


import java.io.IOException;

@WebServlet("/findUserById")
public class FindUserByIdServlet extends HttpServlet {
    private FindUserByIdService findUserByIdService = new FindUserByIdServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String idParam = request.getParameter("id");
        int id = Integer.parseInt(idParam);
        User user = findUserByIdService.findUserById(id);

        response.setContentType("application/json;charset=UTF-8");
        response.getWriter().write(user != null ? user.toString() : "{}");
    }
}
